package com.bitcat.firstapp

import android.app.Application
import android.content.pm.PackageManager
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import es.dmoral.toasty.Toasty


val appContext by lazy { MyApplication.instance }

//MyApplication本质上就是Context
class MyApplication : Application() {


    companion object {
        lateinit var instance: MyApplication

        init {
            //配置全局的下拉刷新样式
            SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
                ClassicsHeader(appContext)
            }
            SmartRefreshLayout.setDefaultRefreshFooterCreator  { context, layout ->
                ClassicsFooter(appContext)
            }
        }
    }


    override fun onCreate() {
        super.onCreate()
        instance = this


        //获取当前是哪一个渠道
//        val channel = BuildConfig.FLAVOR
//        Toasty.info(appContext, "当前渠道是：$channel", Toasty.LENGTH_SHORT).show()

        //方式二 meta -data
        val appInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
        val channel = appInfo.metaData.getString("CHANNEL", "default")
        Toasty.info(this, "当前渠道为：$channel", Toasty.LENGTH_SHORT).show()
    }
}